<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="my" uri="http://www.trkj.com/tr1702/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<script type="text/javascript" src="<c:url value="/js/jquery-easyui-1.5.5.6/jquery.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/jquery-easyui-1.5.5.6/jquery.easyui.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/jquery-easyui-1.5.5.6/locale/easyui-lang-zh_CN.js"/>"></script>
<link rel="stylesheet" type="text/css" href="<c:url value="/js/jquery-easyui-1.5.5.6/themes/default/easyui.css"/>"/>
<link rel="stylesheet" type="text/css" href="<c:url value="/js/jquery-easyui-1.5.5.6/themes/icon.css"/>"/>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>计算规则表（calcluate rule）</title>
</head>
<body>

<script type="text/javascript" >
	//操作按钮
	var computation_rule_button =function(value,row,index){	
		var only ="";
		var edit="";
		var del="";
		<my:g id="176">only= "<a style='' btn='cell_btn_only' onclick='only_computation_rule(" + row.calcluateruleId + ","+row.calcluateruleState +")'></a>";</my:g>
		<my:g id="177">edit = "<a style='' btn='cell_btn_edit' onclick='edit_computation_rule(" + row.calcluateruleId + ","+row.calcluateruleState +","+row.calcluateruleSj +")'></a>";</my:g>
		<my:g id="178"> del = " <a btn='cell_btn_del' onclick='del_computation_rule(" + row.calcluateruleId + ")'></a>";</my:g>
		return  only +edit +del; 
	}
	
	//状态
	var computation_rule_state= function(value,row,index){
		var pic="";
		var state = row.calcluateruleState;
		if(state==0){
			pic = "<input type='checkbox' disabled='disabled'>";
		}else if(state==1){
			pic="<input type='checkbox' checked disabled='disabled'>";
		}
		return pic;
	}
	
	//是否按实际
	var computation_rule_sj= function(value,row,index){
		var pic="";
		var sjstate = row.calcluateruleSj;
		if(sjstate==0){
			pic = "<input type='checkbox' disabled='disabled'>";
		}else if(sjstate==1){
			pic="<input type='checkbox' checked disabled='disabled'>";
		}
		return pic;
	}
	//编辑
	var edit_computation_rule = function(calcluateruleId,calcluateruleState,calcluateruleSj){
		$('#computation_rule_edit_dg').dialog({onOpen:function(){
			if(calcluateruleSj==1){
				$("#computation_edit_asj").attr('checked',"checked")	
			}else if(calcluateruleSj==0){
				$("#computation_edit_asj").attr('checked',false)
			}
			if(calcluateruleState==1){
				$("#computation_edit_shop").attr('checked',"checked")		
			}else if(calcluateruleState==0){
				$("#computation_edit_shop").attr('checked',false)		
			}
			$('#computation_edit_tk_form').form('load','to_calcluate_load?calcluateruleId='+calcluateruleId);
		}});
		//打开编辑页面
		$('#computation_rule_edit_dg').dialog("open");
	}
	
	//禁用
	var only_computation_rule = function(calcluateruleId,calcluateruleState){
		 var jy_state =1;
		//alert(affcaState)
		if(calcluateruleState==1){
			jy_state=0;
			$.messager.confirm('确认', '您确定要打开该事务吗？', function(v){
				if(v){
					$.post("to_calcluate_editstate", {calcluateruleId: calcluateruleId,calcluateruleState:jy_state}, function(v){
						if(v.success){
							$('#lxl_computation_rule_table').datagrid('reload');
							
						}else{
							$.messager.alert('错误', v.message);
						}
					});
					
				}else{
					
				}
				
			}); 
		}else{
			jy_state=1;
			$.messager.confirm('确认', '您确定要关闭该事务吗？', function(v){
				if(v){
					$.post("to_calcluate_editstate", {calcluateruleId: calcluateruleId,calcluateruleState:jy_state}, function(v){
						if(v.success){
							$("#lxl_computation_rule_table").datagrid("reload");
							
						}else{
							$.messager.alert('错误', v.message);
						}
					});
				}else{
					
				}
				
			}); 
		}
	}
	
	//删除
	var del_computation_rule=function(calcluateruleId){
		$.messager.confirm("确认","你确认要删除吗？",function(v){
			if(v){
				$.post("to_calcluate_delete",{calcluateruleId:calcluateruleId},function(v){
					if(v.success){
						$("#lxl_computation_rule_table").datagrid("reload");
					}else{
						$.messager.alert("错误",v.messager);
					}
				});
			}else{
				
			}
		});
	}
	$(function(){
		//操作图标
		$("#lxl_computation_rule_table").datagrid({
			onLoadSuccess:function(){
				$("a[btn=cell_btn_edit]").linkbutton({iconCls:'icon-update_red', plain:true});
				$("a[btn=cell_btn_del]").linkbutton({iconCls:'icon-delete_red', plain:true});
				$("a[btn=cell_btn_only]").linkbutton({iconCls:'icon-changes', plain:true});
			}
		});
		//模糊查询
		$("#computation_rule_seebyname").linkbutton({onClick:function(){
			var seekText = $("#computation_rule_seebytext").textbox("getText");
			$("#lxl_computation_rule_table").datagrid({url:'to_calcluate_like?calcluateruleName='+seekText,method:'post'});
			$("#lxl_computation_rule_table").datagrid("reload");
		}});
		
		//打开新增页面
		$(".add_computation_rule").linkbutton({
			onClick : function() {
				$("#computation_rule_add_dg").dialog("open");
			}
		});
	});
	
	
	$.extend($.fn.validatebox.defaults.rules,{
		hours:{
	    	validator: function(value,param){     
	        return /^\+?[1-9][0-9]*$/.test(value);     
	      },     
	        message: '只能输入正整数！'    
	    },
	});
	 
</script>
<table id="lxl_computation_rule_table" width="100%" class="easyui-datagrid" style="width: 400px;"
		data-options="
				fitColumns:true,
				fit:true,
       			url:'to_calcluate_findall',
				pagination:true,     
				pageSize:5,     
				pageList: [5,10,15,20,25], 
				rownumbers:true,
				Striped:true, 
				singleSelect:true,
				toolbar:'#tool_computation_rule_gj'
        ">
		<thead>
			<tr>
				<th width="5%" data-options="field:'calcluateruleId',align:'center'">编号</th>
				<th width="10%" data-options="field:'calcluateruleName',align:'center'">名称</th>
				<th width="10%" data-options="field:'calcluateruleCount',align:'center'">一天工作小时数</th>
				<th width="10%" data-options="field:'calcluateruleSj',align:'center',formatter:computation_rule_sj">按实际</th>
				<th width="10%" data-options="field:'calcluateruleRemarks',align:'center'">备注</th>
				<th width="10%" data-options="field:'calcluaterulePerson',align:'center'">创建者</th>
				<th width="14%" data-options="field:'calcluateruleCjdate',align:'center'
				,formatter:function(value,row,index){
					if(value!=null){
						var date = new Date(value);
						return date.toLocaleString();
					}
						return;
				}">创建日期</th>
				<th width="15%" data-options="field:'calcluateruleUpdatetime',align:'center',formatter:function(value,row,index){
					if(value!=null){
						var date = new Date(value);
						return date.toLocaleString();
					}
						return;
				}">更新日期</th>
				<th width="5%" data-options="field:'calcluateruleState',align:'center',formatter:computation_rule_state">
					状态
				</th>
				<th width="10%" data-options="field:'calcluaterulecaoz',align:'center',formatter:computation_rule_button">操作</th>   
			</tr>
		</thead>
		<tbody>
		</tbody>
	</table>
	<!--工具-->
	<div id="tool_computation_rule_gj" style="padding-left: 30px;">
		<my:g id="45"><a class="easyui-linkbutton add_computation_rule" data-options="iconCls:'icon-add'">新增</a></my:g>
		<a id="computation_rule_reload_bt" class="easyui-linkbutton" data-options="iconCls:'icon-reload'"></a>
		<input class="easyui-textbox" id="computation_rule_seebytext" data-options="prompt:'请输入名称'"/>
		<a class="easyui-linkbutton" data-options="text:'搜索'" id="computation_rule_seebyname"> </a>
	</div>
	
	<!-- 新增 -->
	<div id="computation_rule_add_dg" class="easyui-dialog" title="假种新增"
		data-options="
         width:440,
	     resizable:false,
	     modal:true,
	     closed:true,
	     buttons:[{
				text:'添加',
				width:60,
				handler:function(){
					$('#computation_rule_tk_form').form({
						url:'to_calcluate_add',
						
						onSubmit:function(params){
							
							params['calcluateruleName']=$('#computation_rule_name').textbox('getText');
							params['calcluateruleCount']=$('#computation_rule_count').textbox('getText');
							params['calcluateruleRemarks']=$('#computation_rule_marks').textbox('getText');
							if($('#computation_rule_asj').is(':checked')){
								params['calcluateruleSj']=parseInt(1);
							}else{
								params['calcluateruleSj']=parseInt(0);
							}
							if($('#computation_rule_shop').is(':checked')){
								params['calcluateruleState']=parseInt(1);
							}else{
								params['calcluateruleState']=parseInt(0);
							}
							return $('#computation_rule_tk_form').form('validate');
						},
						success:function(v){
							v = eval('('+v +')');
							if(v.success){
								$.messager.alert('恭喜', '添加成功');
							}else{
								$.messager.alert('错误', '对不起，操作失败，原因：' + v.message);
							}
						$.messager.progress('close');// 如果提交成功则隐藏进度条
						$('#lxl_computation_rule_table').datagrid('reload');
						$('#computation_rule_tk_form').form('reset');
						$('#computation_rule_add_dg').dialog('close');
						}
					}).submit();
				}
				},{
				text:'继续添加',
				width:80,
				handler:function(){
					$('#computation_rule_tk_form').form({
						url:'to_calcluate_add',
						
						onSubmit:function(params){
							
							params['calcluateruleName']=$('#computation_rule_name').textbox('getText');
							params['calcluateruleCount']=$('#computation_rule_count').textbox('getText');
							params['calcluateruleRemarks']=$('#computation_rule_marks').textbox('getText');
							if($('#computation_rule_asj').is(':checked')){
								params['calcluateruleSj']=parseInt(1);
							}else{
								params['calcluateruleSj']=parseInt(0);
							}
							if($('#computation_rule_shop').is(':checked')){
								params['calcluateruleState']=parseInt(1);
							}else{
								params['calcluateruleState']=parseInt(0);
							}
							return $('#computation_rule_tk_form').form('validate');
						},
						success:function(v){
							v = eval('('+v +')');
							if(v.success){
								$.messager.alert('恭喜', '添加成功');
							}else{
								$.messager.alert('错误', '对不起，操作失败，原因：' + v.message);
							}
						$.messager.progress('close');// 如果提交成功则隐藏进度条
						$('#lxl_computation_rule_table').datagrid('reload');
						$('#computation_rule_tk_form').form('reset');
						
						}
					}).submit();
				}
				},{
				text:'取消',
				width:60,	
				handler:function(){
					$('#computation_rule_add_dg').dialog('close');
				}
			}]
        ">
		<div style="margin-left: 21%; margin-top: 10px;">
			<form action="" id="computation_rule_tk_form" style="text-align: right;">
				<table>
					<tr>
						<td><span style="color: red;">*</span>名称</td>
						<td><input class="easyui-textbox"
							data-options="required:true" id="computation_rule_name"></td>
					</tr>
					<tr>
						<td><span style="color: red;">*</span>一天工作小时数</td>
						<td><input class="easyui-textbox"
							data-options="" id="computation_rule_count" validType="hours"></td>
					</tr>
					
					<tr>
						<td><span style="color: red;"> </span>备注</td>
						<td><input class="easyui-textbox" data-options="height:60,multiline:true" id="computation_rule_marks"></td>
					</tr>
					<tr>
						<td style="width:70px">按实际
						<input type="checkbox" value='0' id="computation_rule_asj"></td>
						<td style="width:70px;float:left">停用
						<input type="checkbox" value='0' id="computation_rule_shop">
					</tr>
				</table>
			</form>
		</div>
	</div>
	
	<!-- 编辑 -->
	<div id="computation_rule_edit_dg" class="easyui-dialog" title="假种编辑"
		data-options="
         width:440,
	     resizable:false,
	     modal:true,
	     closed:true,
	     buttons:[{
				text:'更新',
				width:60,
				handler:function(){
					$('#computation_rule_tk_form').form({
					url:'to_calcluate_edit',
						onSubmit:function(params){
					
							params['calcluateruleId']=$('#computation_edit_id').textbox('getText');
							params['calcluateruleName']=$('#computation_edit_name').textbox('getText');
							params['calcluateruleCount']=$('#computation_edit_count').textbox('getText');
							params['calcluateruleRemarks']=$('#computation_edit_marks').textbox('getText');
							if($('.computation_edit_asj').is(':checked')){
								params['calcluateruleSj']=parseInt(1);
							}else{
								params['calcluateruleSj']=parseInt(0);
							}
							if($('#computation_edit_shop').is(':checked')){
								params['calcluateruleState']=parseInt(1);
							}else{
								params['calcluateruleState']=parseInt(0);
							}
							return $('#computation_edit_tk_form').form('validate');
						},
						success:function(v){
							v = eval('('+v +')');
							if(v.success){
								$.messager.alert('恭喜', '修改成功');
							}else{
								$.messager.alert('错误', '对不起，操作失败，原因：' + v.message);
							}
						$.messager.progress('close');// 如果提交成功则隐藏进度条
						$('#lxl_computation_rule_table').datagrid('reload');
						$('#computation_rule_tk_form').form('reset');
						$('#computation_rule_edit_dg').dialog('close');
						}
					}).submit();
				}
				},{
				text:'取消',
				width:60,	
				handler:function(){
					$('#computation_rule_edit_dg').dialog('close');
				}
			}]
        ">
		<div style="margin-left: 21%; margin-top: 10px;">
			<form action="" id="computation_edit_tk_form" class="computation_edit_tk_form" style="text-align: right;">
				<table>
					<tr style="display:none">
						<td><span style="color: red;">*</span>id</td>
						<td><input class="easyui-textbox" name="calcluateruleId"
							data-options="required:true" id="computation_edit_id"></td>
					</tr>
					<tr>
						<td><span style="color: red;">*</span>名称</td>
						<td><input class="easyui-textbox" name="calcluateruleName"
							data-options="required:true" id="computation_edit_name"></td>
					</tr>
					<tr>
						<td><span style="color: red;">*</span>一天工作小时数</td>
						<td><input class="easyui-textbox" name="calcluateruleCount"
							data-options=""  id="computation_edit_count" validType="hours"></td>
					</tr>
					
					<tr>
						<td><span style="color: red;"> </span>备注</td>
						<td><input class="easyui-textbox" data-options="height:60,multiline:true"
						 id="computation_edit_marks" name="calcluateruleRemarks"></td>
					</tr>
					<tr>
						<td style="width:70px">按实际
						<input type="checkbox" id="computation_edit_asj" class="computation_edit_asj"/></td>
						<td style="width:70px;float:left">停用
						<input type="checkbox" value='1' name="calcluateruleState" id="computation_edit_shop" class="computation_edit_shop"/></td>
					</tr>
				</table>
			</form>
		</div>
	</div>
</body>
</html>